package ucm.module;
import air_cp5620.dao.DAO;
import javax.swing.JOptionPane;
import java.sql.*;

public class UC_DelM {
    private String name = null;
    private String passwod = null;
    private DAO dbCon = null;

    public UC_DelM(String name, String passwod) {
        this.name = name;
        this.passwod = passwod;
        dbCon = new DAO();
    }


    public boolean delete()
    {
        String sql = null;
        Connection con = dbCon.getConnection();
        if (con == null) {
            return false;
        }
        try {
            Statement stmt = con.createStatement(ResultSet.CONCUR_UPDATABLE, ResultSet.CONCUR_UPDATABLE);
            sql = "select * from tbl_user where userid ='" + name + "'";
            ResultSet res = stmt.executeQuery(sql);
            
            res.first();
            if (passwod.equals(res.getString("password"))) {
                 stmt.executeUpdate("update tbl_user set isdelete='1' WHERE userid = '" + name + "'");
                 JOptionPane.showMessageDialog(null, "Deleted successfully");
                 return true;
            }
            else {
                JOptionPane.showMessageDialog(null, "Password Error");
                return false;
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Does not have the user");
            return false;
        }
    }
}
